package org.bigjava.travel.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.bigjava.travel.bean.Hotel;
import org.bigjava.travel.dao.HotelDao;
import org.bigjava.travel.service.HotelService;
import org.bigjava.travel.utils.Tools;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 酒店业务逻辑层实现类
 */
@Service
public class HotelServiceImpl implements HotelService {

    @Resource
    HotelDao hotelDao;

    @Override
    public long count() throws Exception {
        return hotelDao.count();
    }

    @Override
    public Hotel findById(Integer id) throws Exception {
        return hotelDao.findById(id);
    }

    @Override
    public List<Hotel> findList() throws Exception {
        return hotelDao.findList();
    }

    @Override
    public void save(Hotel hotel) throws Exception {
        hotelDao.save(hotel);
    }

    @Override
    public void update(Hotel hotel) throws Exception {
        hotelDao.update(hotel);
    }

    @Override
    public void deleteById(Integer id) throws Exception {
        hotelDao.deleteById(id);
    }

    @Override
    public List<Hotel> findByPage(int currentPage, int pageSize, String query) {
        List<Hotel> list = new ArrayList<Hotel>();
        PageHelper.startPage(currentPage, pageSize);
        if (Tools.notEmpty(query)) {
            list = hotelDao.findListByQuery("%" + query + "%");
        } else {
            list = hotelDao.findList();
        }
        PageInfo<Hotel> pageInfo=new PageInfo<Hotel>(list);
        return pageInfo.getList();
    }

    @Override
    public List<Hotel> findByPage(int currentPage, int pageSize) {
        List<Hotel> list = new ArrayList<Hotel>();
        PageHelper.startPage(currentPage, pageSize);
        list = hotelDao.indexList();
        PageInfo<Hotel> pageInfo=new PageInfo<Hotel>(list);
        return pageInfo.getList();
    }

    @Override
    public long state0count() throws Exception {
        return hotelDao.state0count();
    }

    @Override
    public long state1count() throws Exception {
        return hotelDao.state1count();
    }

    @Override
    public long state2count() throws Exception {
        return hotelDao.state2count();
    }

    @Override
    public long count2() throws Exception {
        return hotelDao.count2();
    }
}
